<?php 
class OffsalesController extends AppController{
var $name = "Offsales";
var $helpers = array('Html','Ajax','Javascript','Form','Session');
var $paginate = array(
        'limit' =>10,
        'order' => array('Offsale.product_id' => 'asc')
    );
var	$uses = array('Offsale','Product');
function index($id = null){
	$this->Offsale->id = $id;
	$this->layout = "home";
	$this->set('iOffsale',$this->Offsale->read());
	$this->set('product',$this->Product->find('all'));
	
	$data = $this->paginate('Offsale');
        $this->set('Offsales', $data);
}
function save(){
	$id=$_REQUEST['id'];
	$product_id = $_REQUEST['product_id'];
	$type=$_REQUEST['type'];
	$new_price=$_REQUEST['new_price'];
	$begin_date = $_REQUEST['begin_date'];
	$end_date =$_REQUEST['end_date'];
	$description=$_REQUEST['description'];
	$status =$_REQUEST['status'];
	if($id !=null && $id !=""){
		$this->Offsale->set('id',$id);
		$this->Offsale->set('product_id',$product_id);
		$this->Offsale->set('type',$type);
		$this->Offsale->set('new_price',$new_price);
		$this->Offsale->set('begin_date',$begin_date);
		$this->Offsale->set('end_date',$end_date);
		$this->Offsale->set('description',$description);
		$this->Offsale->set('status',$status);
		$this->Offsale->save();
	}else{
			$this->Offsale->create();
			$this->Offsale->set('product_id',$product_id);
			$this->Offsale->set('type',$type);
			$this->Offsale->set('new_price',$new_price);
			$this->Offsale->set('begin_date',$begin_date);
			$this->Offsale->set('end_date',$end_date);
			$this->Offsale->set('description',$description);
			$this->Offsale->set('status',$status);
			$this->Offsale->saveAll();
	}
	$this->redirect(array("action" => "index", $this->Offsale->id));
	}
function delete() {
		$id= $_REQUEST['id'];
		if($id !=null && $id !=""){
		$this->Offsale->delete($id);
		$this->redirect(array('action'=>'index'));
		}
}
}
?>